#include "javascrp.h"

#define TOKEN_GROW  (16)

typedef struct  TMarkup
    {
    int         Classes;
    int         Id;
    TToken      Token;
    }           TMarkup;

static TMarkup* Tokens;
static int      TokenCount;
static int      TokenSize;


static
void    GrowTokens(void)
    {
    int     NewSize = TokenSize + TOKEN_GROW;

    Tokens  = realloc(Tokens, NewSize * sizeof(TMarkup));
    assert(Tokens != NULL);
    TokenSize   = NewSize;
    }

void    JsAdd(TToken Token)
    {
    if(TokenCount >= TokenSize)
        GrowTokens();
    Tokens[TokenCount++].Token  = Token;
    }

static
int     compare(const void* A, const void* B)
    {
    ptrdiff_t   Diff;

    Diff    = ((TMarkup*)A)->Token.Text - ((TMarkup*)B)->Token.Text;

    if(Diff < 0)
        return -1;
    else if(Diff == 0)
        return 0;
    else
        return 1;
    }

static
int     FindToken(TToken Token)
    {
    TMarkup*    Found;

    Found   = bsearch(Token.Text, Tokens, TokenCount, sizeof(TMarkup), compare);
    if(Found)
        return (int)((TMarkup*)Found - Tokens);
    else
        return -1;
    }

void    JsMarkClass(TToken Token, int Class)
    {
    }
void    JsMarkId(TToken Token, int Id)
    {
    }

static
void    FrameSymbols(FILE* Out)
    {
    }

static
void    FrameSource(FILE* Out)
    {
    }

void    JsWrite(const char* Filename)
    {
    FILE*   Out;

    Out = fopen(Filename, "w");
    fprintf(Out, "<html><head></head><frameset cols=\"25%,*\">\n");
    fprintf(Out, "    <frame name=\"symbols\">\n");
    FrameSymbols(Out);
    fprintf(Out, "    </frame>\n");
    fprintf(Out, "    <frame name=\"source\">\n");
    FrameSource(Out);
    fprintf(Out, "    </frame>\n");

    fprintf(Out, "</frameset></html>\n");
    fclose(Out);
    }

